<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>创建候选人</span>
      </div>
      <el-form :model="form" :rules="rules" ref="form" label-width="200px" style="width: 500px">
        <el-form-item label="面试岗位" prop="jobId">

          <el-select v-model="form.jobId" placeholder="请选择面试岗位">
            <el-option
                v-for="item in jobList"
                :key="item.id"
                :label="item.jobName"
                :value="item.id">
            </el-option>
          </el-select>


        </el-form-item>
        <el-form-item label="姓名" prop="realName">
          <el-input v-model="form.realName"></el-input>
        </el-form-item>
        <el-form-item label="身份证号码" prop="identityNum">
          <el-input v-model="form.identityNum"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option label="男" value="1"></el-option>
            <el-option label="女" value="0"></el-option>
            <el-option label="未知" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机号" prop="mobile">
          <el-input v-model="form.mobile"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email"></el-input>
        </el-form-item>
        <el-form-item label="出生日期" prop="birthday">
          <el-date-picker v-model="form.birthday" type="date" placeholder="请选择出生日期"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">立即提交</el-button>
          <el-button @click="resetForm">取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>


import jobList from "@/components/Job/JobList.vue";
import http from '@/http.js'; // 导入封装好的axios实例
export default {
  computed: {
    jobList() {
      return jobList
    }
  },
  data() {
    return {
      jobList: [],
      form: {},
      rules: {
        interviewPosition: [
          {required: true, message: '请选择面试岗位', trigger: 'change'}
        ],
        name: [
          {required: true, message: '姓名不能为空', trigger: 'blur'}
        ],
        idNumber: [
          {required: true, message: '身份证号码不能为空', trigger: 'blur'}
        ],
        gender: [
          {required: true, message: '请选择性别', trigger: 'change'}
        ],
        phone: [
          {required: true, message: '手机号不能为空', trigger: 'blur'}
        ],
        email: [
          {required: true, message: '邮箱不能为空', trigger: 'blur'}
        ],
        birthDate: [
          {required: true, message: '请选择出生日期', trigger: 'change'}
        ]
      }
    };
  },

  created() {
    // 在组件创建时，可以调用获取数据的方法
    http.get('/job/listAllJob').then(res => {
      this.jobList = res;
    })
  },
  methods: {
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          // 在这里可以添加提交表单数据的逻辑，例如发送AJAX请求
          http.post('/candidate/saveCandidate', this.form).then(res => {
            this.$router.push('/candidateList');
          })
          console.log('表单提交成功', this.form);
        } else {
          console.log('表单验证失败');
          return false;
        }
      });
    },
    resetForm() {
      this.$refs.form.resetFields();
    }
  }
};
</script>

<style scoped>
.box-card {
  margin-bottom: 20px;
}
</style>